// pages/user/business-invite/business-invite.js
import painter from '../../../utils/painterImage/image.js';
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    template: {},
    shareImage: '',
  },

  //获取二维码接口
  getQr(){
    let _this = this;
    let user = app.getUser();

    let path = 'sub/user/joinMerchant/joinMerchant';
    app.requestUrl({
      method: 'POST',
      url: '/wxapi/qr/appCode',
      data: {
        flag: 2,
        url: path,
        upShopId: '',
        upCentreId: '',
        goodsId: '',
        centreId: user.centreId,
        cd: '',
        userId: user.id,
      },
      header: {
        'Content-Type': 'application/json;charset=UTF-8',
        'Authorization': wx.getStorageSync('authToken') || 'empty-token'
      },
    }).then(res =>{
      let tempQr = res.data.date;
      _this.setData({
        template: new painter().shopShare('https://o.rjkj7.com/data/upload/xcximages/qr_back_1.png','https://o.rjkj7.com/data/upload/xcximages/qr_back_2.png',user.nickname,user.avatar,tempQr),
      })
    })

  },

  onImgOK(e) {
    this.setData({
      shareImage: e.detail.path
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getQr();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var _this = this;
    let share = app.getShareData();
    let user = app.getUser();
    return{
      title: user.nickname + ',邀请你成为商户',
      path: '/sub/user/joinMerchant/joinMerchant?upid=' + user.id,
      success: function () {

      },
      fail: function () {
        wx.showToast({title: '分享失败',icon: 'none'})
      }
    }
  }
})